import pickle
# 1.list 序列化
a = [1, 2, 3, 4, 5, 6, 8, "111", "222", "333"]
with open("list.pkl", "wb") as f:
    pickle.dump(a, f)

with open("list.pkl", "rb") as f:
    b = pickle.load(f)
    print(b)


# 2.dict 序列化
c = {"name": "zhangsan", "age": 18, "sex": "male"}
with open("dict.pkl", "wb") as f:
    pickle.dump(c, f)

with open("dict.pkl", "rb") as f:
    d = pickle.load(f)
    print(d)


# 3.class 序列化
class Person:
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

    def say(self):
        print(f"my name is {self.name}, i am {self.age} years old, i am {self.sex}")

e = Person("zhangsan", 18, "male")
with open("class.pkl", "wb") as f:
    pickle.dump(e, f)

with open("class.pkl", "rb") as f:
    f1 = pickle.load(f)
    f1.say()
